<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <title>nginx | JAVA</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="负载均衡">
  
  
  
  
  <meta name="description" content="Nginx准备工作 打开官网http://nginx.org/下载nginx  nginx-1.19.5.tar.gz   安装 openssl  、zlib  、 gcc  依赖  yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel   联网下载 pcre  压缩文件依赖   1、wget http:">
<meta name="keywords" content="负载均衡">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx">
<meta property="og:url" content="https://jameslin23.gitee.io/2020/12/01/ngnix/index.html">
<meta property="og:site_name" content="JAVA">
<meta property="og:description" content="Nginx准备工作 打开官网http://nginx.org/下载nginx  nginx-1.19.5.tar.gz   安装 openssl  、zlib  、 gcc  依赖  yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel   联网下载 pcre  压缩文件依赖   1、wget http:">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202144955232.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202145725518.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202145811683.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202150043431.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix/C:%5CUsers%5CAdministrator.USER-20190627HM%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20201224085740670.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix/C:%5CUsers%5CAdministrator.USER-20190627HM%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20201224091808770.png">
<meta property="og:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202152503644.png">
<meta property="og:updated_time" content="2021-02-05T00:40:45.741Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Nginx">
<meta name="twitter:description" content="Nginx准备工作 打开官网http://nginx.org/下载nginx  nginx-1.19.5.tar.gz   安装 openssl  、zlib  、 gcc  依赖  yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel   联网下载 pcre  压缩文件依赖   1、wget http:">
<meta name="twitter:image" content="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202144955232.png">
  
    <link rel="alternate" href="/atom.xml" title="JAVA" type="application/atom+xml">
  

  

  <link rel="icon" href="/css/images/mylogo.jpg">
  <link rel="apple-touch-icon" href="/css/images/mylogo.jpg">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt; src:url("/css/fonts/FuturaPTBold.otf") format("woff");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt-light; src:url("/css/fonts/FuturaPTBook.otf") format("woff");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt-italic; src:url("/css/fonts/FuturaPTBookOblique.otf") format("woff");font-weight:400;font-style:italic;}
}

  </style>
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css">

  
    <link rel="stylesheet" href="/css/dialog.css">
  

  

  
    <link rel="stylesheet" href="/css/header-post.css">
  

  
  
  
    <link rel="stylesheet" href="/css/vdonate.css">
  

</head>
</html>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  
  <div id="container">
    <div id="wrap">
      
        <header>

    <div id="allheader" class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="navbar-inner">
          
          <div class="container"> 
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>

            
              <a class="brand" style="border-width: 0;">
                <p>JAVA</p>
              </a>
            
            
            <div class="navbar-collapse collapse">
              <ul class="hnav navbar-nav">
                
                  <li> <a class="main-nav-link" href="/">首页</a> </li>
                
                  <li> <a class="main-nav-link" href="/archives">归档</a> </li>
                
                  <li> <a class="main-nav-link" href="/categories">分类</a> </li>
                
                  <li> <a class="main-nav-link" href="/tags">标签</a> </li>
                
                  <li> <a class="main-nav-link" href="/about">关于</a> </li>
                
                  <li><div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder>
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词...">
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(无标题)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div></li>
            </ul></div>
          </div>
                
      </div>
    </div>

</header>



      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-ngnix" style="width: 75%; float:left;" class="article article-type-post" itemscope itemprop="blogPost">
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      Nginx
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/12/01/ngnix/" class="article-date">
	  <time datetime="2020-12-01T06:55:34.000Z" itemprop="datePublished">2020-12-01</time>
	</a>

      
    <a class="article-category-link" href="/categories/负载均衡/">负载均衡</a>

      
	<a class="article-views">
	<span id="busuanzi_container_page_pv">
		阅读量<span id="busuanzi_value_page_pv"></span>
	</span>
	</a>

      

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="Nginx"><a href="#Nginx" class="headerlink" title="Nginx"></a>Nginx</h1><h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><ol>
<li><p>打开官网<a href="http://nginx.org/下载nginx" target="_blank" rel="noopener">http://nginx.org/下载nginx</a></p>
<blockquote>
<p>nginx-1.19.5.tar.gz</p>
</blockquote>
</li>
<li><p>安装 openssl  、zlib  、 gcc  依赖</p>
<blockquote>
<p>yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel</p>
</blockquote>
</li>
<li><p>联网下载 pcre  压缩文件依赖</p>
<blockquote>
<p> 1、wget <a href="http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz" target="_blank" rel="noopener">http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz</a></p>
<p>2、tar –xvf pcre-8.37.tar.gz</p>
<p>3、./configure</p>
<p>4、install &amp;&amp; make install</p>
</blockquote>
</li>
<li><p>安装 nginx</p>
<blockquote>
<p>1、tar -xvf nginx-1.19.5.tar.gz</p>
<p>2、./configure</p>
<p>3、install &amp;&amp; make instal</p>
</blockquote>
</li>
</ol>
<ol start="5">
<li><p>启动nginx</p>
<blockquote>
<p>先关闭防火墙，测试可以全部关掉，生产按照端口开发</p>
</blockquote>
<p>停止firewall</p>
<blockquote>
<p>systemctl stop firewalld.service</p>
</blockquote>
<p>禁止firewall开机启动</p>
<blockquote>
<p>systemctl disable firewalld.service</p>
</blockquote>
<p>查看防火墙状态</p>
<blockquote>
<p>firewall-cmd –state</p>
</blockquote>
<p>进入/usr/local/nginx/sbin/nginx 启动命令</p>
<blockquote>
<p>./nginx</p>
</blockquote>
<p><img src="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202144955232.png" alt="image-20201202144955232"></p>
</li>
<li><p>可配置环境变量</p>
<p>vim /etc/profile</p>
<blockquote>
<p>PATH=$PATH:/usr/local/webserver/nginx/sbin<br>export PATH</p>
</blockquote>
<p>生效 source  /etc/profile</p>
</li>
<li><p>ngnix常用命令</p>
<blockquote>
<p>1、查看版本号</p>
<p>nginx -v</p>
<p>2、启动</p>
<p>nginx</p>
<p>3、停止</p>
<p>nginx -s stop</p>
<p>4、重新加载</p>
<p>nginx -s reload</p>
</blockquote>
<h1 id="反向代理配置"><a href="#反向代理配置" class="headerlink" title="反向代理配置"></a>反向代理配置</h1><h2 id="反向代理-1"><a href="#反向代理-1" class="headerlink" title="反向代理-1"></a>反向代理-1</h2><p><img src="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202145725518.png" alt="image-20201202145725518"></p>
</li>
</ol>
<h2 id="反向代理-2"><a href="#反向代理-2" class="headerlink" title="反向代理-2"></a>反向代理-2</h2><p>   根据不同请求路径对应不同服务器</p>
<p>   <img src="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202145811683.png" alt="image-20201202145811683"></p>
<h1 id="负载均衡"><a href="#负载均衡" class="headerlink" title="负载均衡"></a>负载均衡</h1><h2 id="负载均衡算法"><a href="#负载均衡算法" class="headerlink" title="负载均衡算法"></a>负载均衡算法</h2><h3 id="轮询-默认"><a href="#轮询-默认" class="headerlink" title="轮询(默认)"></a>轮询(默认)</h3><blockquote>
<p>每个请求按时间顺序逐一分配到不同的后端服务器，如果后端服务器 down 掉，能自动剔除。</p>
</blockquote>
<h3 id="weight权重"><a href="#weight权重" class="headerlink" title="weight权重"></a>weight权重</h3><blockquote>
<p>weight 代表权,重默认为 1,权重越高被分配的客户端越多</p>
</blockquote>
<h3 id="ip-hash"><a href="#ip-hash" class="headerlink" title="ip_hash"></a>ip_hash</h3><blockquote>
<p>每个请求按方位ip的hash结果分配，这样每个访客固定一个后端服务器,可以解决session的问题</p>
</blockquote>
<h3 id="fair"><a href="#fair" class="headerlink" title="fair"></a>fair</h3><blockquote>
<p>按照后端服务器的响应时间来分配请求，响应时间短的优先分配</p>
</blockquote>
<h2 id="HTTP-负载均衡"><a href="#HTTP-负载均衡" class="headerlink" title="HTTP 负载均衡"></a>HTTP 负载均衡</h2><p><img src="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202150043431.png" alt="image-20201202150043431"></p>
<h2 id="TCP-负载均衡"><a href="#TCP-负载均衡" class="headerlink" title="TCP 负载均衡"></a>TCP 负载均衡</h2><blockquote>
<p>nginx-1.17.9使用增加了stream 模块用于一般的TCP 代理和负载均衡，ngx_stream_core_module 这个模块在1.90版本后将被启用。但是并不会默认安装</p>
</blockquote>
<p>到nginx源文件目录</p>
<blockquote>
<p>./configure  –with-stream</p>
<p>make &amp; make install</p>
</blockquote>
<p>修改 配置文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">stream &#123;</span><br><span class="line">     upstream kevin &#123;</span><br><span class="line">     server 192.168.10.10:8080; #这里配置成要访问的地址</span><br><span class="line">     server 192.168.10.20:8081;</span><br><span class="line">     &#125;</span><br><span class="line">     server &#123;</span><br><span class="line">     listen 8081; #需要监听的端口</span><br><span class="line">     proxy_timeout 20s;</span><br><span class="line">     proxy_pass kevin;</span><br><span class="line">     &#125;</span><br><span class="line">    # 多个模块可增加多个sever+upstream</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="TCP负载算法"><a href="#TCP负载算法" class="headerlink" title="TCP负载算法"></a>TCP负载算法</h3><h4 id="轮询（默认）"><a href="#轮询（默认）" class="headerlink" title="轮询（默认）"></a>轮询（默认）</h4><h4 id="least-connected"><a href="#least-connected" class="headerlink" title="least-connected"></a>least-connected</h4><blockquote>
<p>对应每个请求,nginx plus选择当前连接数最少的server来处理</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">upstream kevin &#123;</span><br><span class="line"> least_conn;</span><br><span class="line"> server 192.168.10.10:8080; #这里配置成要访问的地址</span><br><span class="line"> server <span class="number">192.168</span>.10.20:<span class="number">8081</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="ip-hash-1"><a href="#ip-hash-1" class="headerlink" title="ip_hash"></a>ip_hash</h4><blockquote>
<p> 客户机的IP地址用作散列键，用于确定应该为客户机的请求选择服务器组中的哪个服务器</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">upstream myapp1 &#123;</span><br><span class="line">    ip_hash;</span><br><span class="line">    server srv1.example.com;</span><br><span class="line">    server srv2.example.com;</span><br><span class="line">    server srv3.example.com;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="hash"><a href="#hash" class="headerlink" title="hash"></a>hash</h4><p>普通的hash算法：nginx plus选择这个server是通过user_defined 关键字，就是IP地址：$remote_addr;</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">upstream kevin &#123;</span><br><span class="line"> hash $remote_addr consistent;</span><br><span class="line"> server 192.168.10.10:8080 weight=5; #这里配置成要访问的地址</span><br><span class="line"> server <span class="number">192.168</span>.10.20:<span class="number">8081</span> max_fails=<span class="number">2</span> fail_timeout=<span class="number">30</span>s;</span><br><span class="line"> server 192.168.10.30:8081 max_conns=3; #需要代理的端口，在这里我代理一一个kevin模块的接口8081</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="静态分离"><a href="#静态分离" class="headerlink" title="静态分离"></a>静态分离</h1><p>待编辑</p>
<h1 id="nginx限流"><a href="#nginx限流" class="headerlink" title="nginx限流"></a>nginx限流</h1><p>nginx提供两种限流的方式</p>
<ul>
<li><strong>控制速率</strong></li>
<li><strong>控制并发连接数</strong></li>
</ul>
<h2 id="控制速率"><a href="#控制速率" class="headerlink" title="控制速率"></a>控制速率</h2><p><strong>原理</strong></p>
<p>采用漏桶算法实现控制速率限流</p>
<p>漏桶(Leaky Bucket) 算法思路很简单，水(请求)先进入到漏桶里，漏桶以一定的速度出水(接口有响应速率),当水流入速度过大会直接溢出（访问频率超过接口响应速率），然后就拒绝请求，可以看出漏桶算法能强行限制数据的传输速率。</p>
<p><img src="/2020/12/01/ngnix/C:%5CUsers%5CAdministrator.USER-20190627HM%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20201224085740670.png" alt="image-20201224085740670"></p>
<p><strong>配置1</strong></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">user</span>  root root;</span><br><span class="line"><span class="attribute">worker_processes</span>  <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="section">events</span> &#123;</span><br><span class="line">    <span class="attribute">worker_connections</span>  <span class="number">1024</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="section">http</span> &#123;</span><br><span class="line">    <span class="attribute">include</span>       mime.types;</span><br><span class="line">    <span class="attribute">default_type</span>  application/octet-stream;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#cache</span></span><br><span class="line">    <span class="attribute">lua_shared_dict</span> dis_cache <span class="number">128m</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#限流设置</span></span><br><span class="line">    <span class="attribute">limit_req_zone</span> <span class="variable">$binary_remote_addr</span> zone=contentRateLimit:<span class="number">10m</span> rate=2r/s;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">sendfile</span>        <span class="literal">on</span>;</span><br><span class="line">    <span class="comment">#tcp_nopush     on;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">#keepalive_timeout  0;</span></span><br><span class="line">    <span class="attribute">keepalive_timeout</span>  <span class="number">65</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#gzip  on;</span></span><br><span class="line"></span><br><span class="line">    <span class="section">server</span> &#123;</span><br><span class="line">        <span class="attribute">listen</span>       <span class="number">80</span>;</span><br><span class="line">        <span class="attribute">server_name</span>  localhost;</span><br><span class="line"></span><br><span class="line">        <span class="attribute">location</span> /update_content &#123;</span><br><span class="line">            <span class="attribute">content_by_lua_file</span> /root/lua/update_content.lua;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="attribute">location</span> /read_content &#123;</span><br><span class="line">            <span class="comment">#使用限流配置</span></span><br><span class="line">            <span class="attribute">limit_req</span> zone=contentRateLimit;</span><br><span class="line">            <span class="attribute">content_by_lua_file</span> /root/lua/read_content.lua;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>配置参数说明</strong></p>
<ul>
<li><strong>binary_remote_addr</strong>: 是一种key,表示基于remote_add(客户端)来做限流，binary_ 目的压缩内存占用量。</li>
<li><strong>zone</strong>: 定义共享内存区来存储访问信息，contentRateLimit:10m 表示一个大小为10m,名字为contentRateLimit的内存区域。1M能存储16000 IP地址访问信息，10M可以存储16万IP地址访问</li>
<li><strong>rate</strong>: 用于设置最大访问速率,rate=10r/s 表示每秒最多处理10请求。nginx实际上以毫秒为颗粒度来跟踪请求信息。因此10r/s实际上是限制每100毫秒处理一个请求。这意味着自上一个请求处理完，若后续100毫秒内又有请求到达，将拒接该请求。我们这里设置为2，方便测试。</li>
</ul>
<p><strong>测试</strong></p>
<p>访问<a href="http://192.168.10.132/read_content?id=1，连续刷新就会报错" target="_blank" rel="noopener">http://192.168.10.132/read_content?id=1，连续刷新就会报错</a></p>
<p><img src="/2020/12/01/ngnix/C:%5CUsers%5CAdministrator.USER-20190627HM%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20201224091808770.png" alt="image-20201224091808770"></p>
<p><strong>配置2</strong></p>
<p>上面例子限制2r/s，如果有时正常流量突然增大，超过的请求将被拒接，无法处理突发流量，可以结合<strong>burst</strong>参数使用来解决该问题</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span>       <span class="number">80</span>;</span><br><span class="line">    <span class="attribute">server_name</span>  localhost;</span><br><span class="line">    <span class="attribute">location</span> /update_content &#123;</span><br><span class="line">        <span class="attribute">content_by_lua_file</span> /root/lua/update_content.lua;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="attribute">location</span> /read_content &#123;</span><br><span class="line">        <span class="attribute">limit_req</span> zone=contentRateLimit burst=<span class="number">4</span>;</span><br><span class="line">        <span class="attribute">content_by_lua_file</span> /root/lua/read_content.lua;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>burst译为突发、爆发，表示在超过设定的处理速率后能额外处理的请求，当rate=10r/s时，将1s拆分10份，既每100ms可以处理1个请求。此处burst=4,若同时有4个请求达到,nginx会处理第一个请求。剩余3个请求将放入队列，然后每隔100ms从队列中获取一个请求进行处理。若请求大于4，将拒接处理多余的请求，直接返回503.</p>
<p>不过，单独使用 burst 参数并不实用。假设 burst=50 ，rate依然为10r/s，排队中的50个请求虽然每100ms会处理一个，但第50个请求却需要等待 50 * 100ms即 5s，这么长的处理时间自然难以接受。</p>
<p>因此，burst往往结合<strong>nodelay</strong> 一起使用</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">limit_req</span> zone=contentRateLimit burst=<span class="number">4</span> nodelay;</span><br></pre></td></tr></table></figure>

<p>平均每秒允许不超过2个请求，突发不超过4个请求，并且处理突发4个请求的时候，没有延迟，等到完成之后，按照正常的速率处理。</p>
<h2 id="控制并发连接数"><a href="#控制并发连接数" class="headerlink" title="控制并发连接数"></a>控制并发连接数</h2><p><strong>配置限制固定连接数</strong></p>
<p>ngx_http_limit_conn_module  提供了限制连接数的能力。主要是利用limit_conn_zone和limit_conn两个指令。</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">http</span> &#123;</span><br><span class="line">    <span class="attribute">include</span>       mime.types;</span><br><span class="line">    <span class="attribute">default_type</span>  application/octet-stream;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#cache</span></span><br><span class="line">    <span class="attribute">lua_shared_dict</span> dis_cache <span class="number">128m</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#限流设置</span></span><br><span class="line">    <span class="attribute">limit_req_zone</span> <span class="variable">$binary_remote_addr</span> zone=contentRateLimit:<span class="number">10m</span> rate=2r/s;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#根据IP地址来限制，存储内存大小10M</span></span><br><span class="line">    <span class="attribute">limit_conn_zone</span> <span class="variable">$binary_remote_addr</span> zone=addr:<span class="number">1m</span>;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">sendfile</span>        <span class="literal">on</span>;</span><br><span class="line">    <span class="comment">#tcp_nopush     on;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">#keepalive_timeout  0;</span></span><br><span class="line">    <span class="attribute">keepalive_timeout</span>  <span class="number">65</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">#gzip  on;</span></span><br><span class="line"></span><br><span class="line">    <span class="section">server</span> &#123;</span><br><span class="line">        <span class="attribute">listen</span>       <span class="number">80</span>;</span><br><span class="line">        <span class="attribute">server_name</span>  localhost;</span><br><span class="line">        <span class="comment">#所有以brand开始的请求，访问本地changgou-service-goods微服务</span></span><br><span class="line">        <span class="attribute">location</span> /brand &#123;</span><br><span class="line">            <span class="attribute">limit_conn</span> addr <span class="number">2</span>;</span><br><span class="line">            <span class="attribute">proxy_pass</span> http://192.168.211.1:18081;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="attribute">location</span> /update_content &#123;</span><br><span class="line">            <span class="attribute">content_by_lua_file</span> /root/lua/update_content.lua;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="attribute">location</span> /read_content &#123;</span><br><span class="line">            <span class="attribute">limit_req</span> zone=contentRateLimit burst=<span class="number">4</span> nodelay;</span><br><span class="line">            <span class="attribute">content_by_lua_file</span> /root/lua/read_content.lua;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>limit_conn_zone $binary_remote_addr zone=addr:10m;  表示限制根据用户的IP地址来显示，设置存储地址为的内存大小10M</p>
<p>limit_conn addr 2;   表示 同一个地址只允许连接2次。</p>
</blockquote>
<p><strong>限制每个客户端IP与服务器的连接数，同时限制与虚拟服务器的连接总数</strong></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">limit_conn_zone</span> <span class="variable">$binary_remote_addr</span> zone=perip:<span class="number">10m</span>;</span><br><span class="line"><span class="attribute">limit_conn_zone</span> <span class="variable">$server_name</span> zone=perserver:<span class="number">10m</span>; </span><br><span class="line"><span class="section">server</span> &#123;  </span><br><span class="line">    <span class="attribute">listen</span>       <span class="number">80</span>;</span><br><span class="line">    <span class="attribute">server_name</span>  localhost;</span><br><span class="line">    <span class="attribute">charset</span> utf-<span class="number">8</span>;</span><br><span class="line">    <span class="attribute">location</span> / &#123;</span><br><span class="line">        <span class="attribute">limit_conn</span> perip <span class="number">10</span>;<span class="comment">#单个客户端ip与服务器的连接数．</span></span><br><span class="line">        limit_conn perserver 100; ＃限制与服务器的总连接数</span><br><span class="line">        <span class="attribute">root</span>   html;</span><br><span class="line">        <span class="attribute">index</span>  index.html index.htm;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Keepalived高可用"><a href="#Keepalived高可用" class="headerlink" title="Keepalived高可用"></a>Keepalived高可用</h1><p><img src="https://jameslin23.gitee.io/2020/12/01/ngnix//image-20201202152503644.png" alt="image-20201202152503644"></p>
<h2 id="安装keepalived"><a href="#安装keepalived" class="headerlink" title="安装keepalived"></a>安装keepalived</h2><p>一种是用yum安装，一种是下载安装包，这里使用yum</p>
<blockquote>
<p> yum install keepalived –y</p>
</blockquote>
<p>安装之后在/etc/keepalived,有个keepalived.conf</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">! Configuration File <span class="keyword">for</span> keepalived</span><br><span class="line"></span><br><span class="line">global_defs &#123;</span><br><span class="line">	notification_email &#123;</span><br><span class="line">		acassen<span class="meta">@firewall</span>.loc</span><br><span class="line">		failover<span class="meta">@firewall</span>.loc</span><br><span class="line">		sysadmin<span class="meta">@firewall</span>.loc</span><br><span class="line">	&#125;</span><br><span class="line">	notification_email_from Alexandre.Cassen<span class="meta">@firewall</span>.loc</span><br><span class="line">	smtp_server <span class="number">192.168</span>.10.8</span><br><span class="line">	smtp_connect_timeout <span class="number">30</span></span><br><span class="line">	router_id LVS_DEVEL</span><br><span class="line">	&#125;</span><br><span class="line">vrrp_script monitor_nginx &#123;</span><br><span class="line">	script <span class="string">"/usr/local/src/nginx_check.sh"</span></span><br><span class="line">	interval 2 #（检测脚本执行的间隔）</span><br><span class="line">	weight 2  #  检测失败（脚本返回非0）则优先级 -2</span><br><span class="line">    fall 2  # 检测连续 2 次失败才算确定是真失败。会用weight减少优先级（1-255之间）</span><br><span class="line">	&#125;</span><br><span class="line">vrrp_instance VI_1 &#123;</span><br><span class="line">	state MASTER # 备份服务器上将 MASTER 改为 BACKUP</span><br><span class="line">	<span class="class"><span class="keyword">interface</span> <span class="title">ens33</span> # 网卡</span></span><br><span class="line"><span class="class">	<span class="title">virtual_router_id</span> 51 # 主、备机的 <span class="title">virtual_router_id</span> 必须相同</span></span><br><span class="line"><span class="class">	<span class="title">priority</span> 100 # 主、备机取不同的优先级，主机值较大，备份机值较小</span></span><br><span class="line"><span class="class">	<span class="title">advert_int</span> 1</span></span><br><span class="line"><span class="class"></span></span><br><span class="line"><span class="class"><span class="title">authentication</span> </span>&#123;</span><br><span class="line">	auth_type PASS</span><br><span class="line">	auth_pass <span class="number">1111</span></span><br><span class="line">&#125;</span><br><span class="line">	virtual_ipaddress &#123;</span><br><span class="line">	  192.168.10.33 #  VRRP H 虚拟地址</span><br><span class="line">	&#125;</span><br><span class="line">	track_script &#123;</span><br><span class="line">        monitor_nginx</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>检测脚本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">A=`ps -C nginx --no-header | wc -l`</span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$A</span> -eq 0 ];<span class="keyword">then</span></span><br><span class="line">    /usr/<span class="built_in">local</span>/webserver/nginx/sbin/nginx  <span class="comment">#尝试重新启动nginx</span></span><br><span class="line">    sleep 1  <span class="comment">#睡眠1秒</span></span><br><span class="line">    <span class="keyword">if</span> [ `ps -C nginx --no-header | wc -l` -eq 0 ];<span class="keyword">then</span></span><br><span class="line">        killall keepalived <span class="comment">#启动失败，将keepalived服务杀死。将vip漂移到其它备份节点</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>

<p>启动keepalived</p>
<blockquote>
<p>systemctl start keepalived.service</p>
</blockquote>
<p>查看状态</p>
<blockquote>
<p>systemctl status keepalived.service</p>
</blockquote>
<p>关闭keeaplived</p>
<blockquote>
<p>systemctl stop keepalived.service</p>
<p>强关进程</p>
<p>pkill keepalived</p>
</blockquote>
<h1 id="问题总结"><a href="#问题总结" class="headerlink" title="问题总结"></a>问题总结</h1><p><strong>1、/etc/keepalived/chk_nginx.sh exited due to signal 15</strong></p>
<blockquote>
<p>vrrp_script interval的值要修改成小于chk_nginx.sh中sleep的值</p>
<p>chk_nginx.sh sleep的值不宜过大最好不要超过3，否则也会出现exited due to signal 15问题，偶尔会出time out问题</p>
</blockquote>

      
    </div>
    <footer class="article-footer">
      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: '打赏支持', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: 'https://raw.githubusercontent.com/iTimeTraveler/iTimeTraveler.github.io/site/source/about/donate/images/WeChanQR.png',
  alipayImage: 'https://raw.githubusercontent.com/iTimeTraveler/iTimeTraveler.github.io/site/source/about/donate/images/AliPayQR.jpg'
});
</script>
      
      
      <div>
        <ul class="post-copyright">
          <li class="post-copyright-author">
          <strong>本文作者:  </strong>LeBron Tao
          </li>
          <li class="post-copyright-link">
          <strong>本文链接:  </strong>
          <a href="/2020/12/01/ngnix/" target="_blank" title="Nginx">https://jameslin23.gitee.io/2020/12/01/ngnix/</a>
          </li>
          <li class="post-copyright-license">
            <strong>版权声明:   </strong>
            本博客所有文章除特别声明外，均采用 <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">CC BY-NC-ND 4.0</a>
            许可协议。转载请注明出处
          </li>
         
        </ul>
<div>
</div></div>
      
      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC8yOTQ4MS82MDQ5">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
      
        
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/负载均衡/">负载均衡</a></li></ul>

      

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/12/04/redis/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          redis
        
      </div>
    </a>
  
  
    <a href="/2020/12/01/RocketMQ/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">RocketMQ</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="toc-sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Nginx"><span class="nav-number">1.</span> <span class="nav-text">Nginx</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#准备工作"><span class="nav-number">1.1.</span> <span class="nav-text">准备工作</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#反向代理配置"><span class="nav-number">2.</span> <span class="nav-text">反向代理配置</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#反向代理-1"><span class="nav-number">2.1.</span> <span class="nav-text">反向代理-1</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#反向代理-2"><span class="nav-number">2.2.</span> <span class="nav-text">反向代理-2</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#负载均衡"><span class="nav-number">3.</span> <span class="nav-text">负载均衡</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#负载均衡算法"><span class="nav-number">3.1.</span> <span class="nav-text">负载均衡算法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#轮询-默认"><span class="nav-number">3.1.1.</span> <span class="nav-text">轮询(默认)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#weight权重"><span class="nav-number">3.1.2.</span> <span class="nav-text">weight权重</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ip-hash"><span class="nav-number">3.1.3.</span> <span class="nav-text">ip_hash</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#fair"><span class="nav-number">3.1.4.</span> <span class="nav-text">fair</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HTTP-负载均衡"><span class="nav-number">3.2.</span> <span class="nav-text">HTTP 负载均衡</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#TCP-负载均衡"><span class="nav-number">3.3.</span> <span class="nav-text">TCP 负载均衡</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#TCP负载算法"><span class="nav-number">3.3.1.</span> <span class="nav-text">TCP负载算法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#轮询（默认）"><span class="nav-number">3.3.1.1.</span> <span class="nav-text">轮询（默认）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#least-connected"><span class="nav-number">3.3.1.2.</span> <span class="nav-text">least-connected</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ip-hash-1"><span class="nav-number">3.3.1.3.</span> <span class="nav-text">ip_hash</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#hash"><span class="nav-number">3.3.1.4.</span> <span class="nav-text">hash</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#静态分离"><span class="nav-number">4.</span> <span class="nav-text">静态分离</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#nginx限流"><span class="nav-number">5.</span> <span class="nav-text">nginx限流</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#控制速率"><span class="nav-number">5.1.</span> <span class="nav-text">控制速率</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#控制并发连接数"><span class="nav-number">5.2.</span> <span class="nav-text">控制并发连接数</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Keepalived高可用"><span class="nav-number">6.</span> <span class="nav-text">Keepalived高可用</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装keepalived"><span class="nav-number">6.1.</span> <span class="nav-text">安装keepalived</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#问题总结"><span class="nav-number">7.</span> <span class="nav-text">问题总结</span></a></li></ol>
    
    </div>
  </aside>

</section>
        
      </div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <p> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/iTimeTraveler/hexo-theme-hiker" target="_blank">Hexo-theme-hiker</a> </p>
	      <p id="copyRightEn">Copyright &copy; 2013 - 2021 JAVA All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				访客数 : <span id="busuanzi_value_site_uv"></span> |  
				访问量 : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>




  <script src="/js/dialog.js"></script>








	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            JAVA
          </div>
          <div class="panel-body">
            Copyright © 2021 LeBron Tao All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
  
    <a id="menu-switch"><i class="fa fa-bars fa-lg"></i></a>
  
</body>
</html>